<div id="top-panel">
    <div id="panel">
        <ul>
            <li><a href="<?php echo site_url("answer"); ?>" class="report_seo">List</a></li>			
        </ul>
    </div>
</div>
<script language="javascript">
	var jq = jQuery.noConflict();
	jq(document).ready(function(){
			var str = '<tr><td>Answer</td>'+
			'<td><textarea name="answer[]" class="input_textarea"></textarea></td></tr>'+
			'<tr><td>Mark</td>'+
			'<td><input type="text" name="mark[]" class="input" /></td></tr>';
			jq(".append").click(function(){
				jq(str).insertBefore('tr.save-tr');
			});
	});
</script>
<div id="wrapper">
	<div id="content">
		<div id="rightnow">
			<h3 class="reallynow">New Item</h3>
			<div>
				<?php echo validation_errors(); ?>
			</div>
			<?php echo form_open('answer/save') ?>
			<input type="hidden" name="id" value="<?php echo isset($answer['id']) ? $answer['id'] : ''; ?>" />
			<table width="100%">
				<tr>
					<td>Question</td>
					<td>
						<select name="question_id" class="input2">
							<?php if(count($question)>0): ?>
							<?php foreach($question as $v): ?>
								<optgroup label="<?php echo $v['title']; ?>">
									<?php if(count($v['quest'])): ?>
									<?php foreach($v['quest'] as $i): ?>
										<option value="<?php echo $i['id']; ?>" <?php if(isset($answer['question_id']) && $answer['question_id']==$i['id']):?> selected="selected" <?php endif; ?>><?php echo $i['question']; ?></option>
									<?php endforeach; ?>
									<?php endif;?>
								</optgroup>								
							<?php endforeach; ?>
							<?php endif; ?>
						</select>						
					</td>
				</tr>
				<tr>
					<td>Answer</td>
					<td><textarea name="answer[]" class="input_textarea"><?php echo isset($answer['answer']) ? $answer['answer'] : '';  ?></textarea></td>
				</tr>
				<tr>
					<td>Mark</td>
					<td><input type="text" name="mark[]" class="input" value="<?php echo isset($answer['mark']) ? $answer['mark'] : '';  ?>" /></td>
				</tr>
				<tr class="save-tr">
					<td>&nbsp;</td>
					<td><input type="submit" value="Save" >
						<input type="button" value="Cancel" class="btcancel" />
						<?php if(!isset($answer['id']) && empty($answer['id'])): ?>
						<a style="cursor:pointer;" class="append"><b><u>New Answer</u></b></a>
						<?php endif; ?>
						</td>
				<tr>
			</table>
		</div>
	</div>
</div>